#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void detab(FILE * s, FILE * d, int w)
{
    char ch;
    int n;
    int pos = 1;

    while ((ch = fgetc(s)) != EOF) {
        switch (ch) {
                case '\t':
                    n = w - (pos-1) % w;
                    for (;n>0; --n) {
                        fputc(' ', d);
                        ++pos;
                    }
                    break;
              case '\n':
                    fputc(ch, d); pos=1; break;

                default:
                    fputc(ch, d); ++pos; break;
        }

    }
}

int main(int argc, char **argv)
{

    int w = 4;
    FILE * fp;



    if (argc < 2) {
        detab(stdin, stdout, w);

    } else {
        while (argc-- > 1) {

            if (**(++argv) == '-') {
                if ((*++(*argv)) == 't') {
                    w = atoi(++*argv);
                }

            } else {
                if ((fp = fopen(*argv, "r")) == NULL) {
                    fprintf(stderr, "文件%s打开失败!\n", *argv);
                    return 1;

                } else {
                    detab(fp, stdout, w);
                    fclose(fp);
                }
            }

        }

        return 0;

    }
}
